/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managerBeans;

import entities.Account;
import java.security.Principal;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import sessionBeans.AccountFacade;

/**
 *
 * @author HOANG ANH
 */
@ManagedBean
@SessionScoped
public class AccountManager {
    @EJB
    private AccountFacade accountFacade;

    private Account account;

    public Account getAccount() {
        if (account == null) {
            Principal principal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
            if (principal != null) {
                account = accountFacade.findbyName(principal.getName());
            }
        }
        return account;
    }



    /** Creates a new instance o
     * f AccountManager */
    public AccountManager() {
    }
}
